package psl;

import java.util.HashMap;
import java.sql.ResultSet;

/**
 * Created by IntelliJ IDEA.
 * User: phiteshkumar
 * Date: Mar 8, 2007
 * Time: 12:55:05 PM
 */
public class LoginPage extends BasePage
{
    public String msUserName;
    public String msPassword;
    public ResultSet moResultSet = null;

    public LoginPage ()
    {
        msViewPage = "LoginPage.jsp";
        msDetailPageId = "SaleEntry";
        msExtraPageId = "Registere";
    }

    public void setRequest (HashMap fhRequest)
    {
        super.setRequest (fhRequest);
        msUserName = (String) mhRequest.get ("username");
        msPassword = (String) mhRequest.get ("password");
    }

    public boolean performLogin ()
    {
        String Qurey = "Select password from customer_new_web Where cid='" + msUserName + "'";
        moResultSet = DBConn.getRecordFromDB (Qurey);
        try
        {
            String password = null;
            while (moResultSet.next ())
            {
                password = moResultSet.getString ("password");
            }
            if (password == null)
            {
                moUserSession.msError = "UserName Is Invalid";
            }
            else if (Encryptor.decrypt (password, AppConstants.ENCRYPTOR_kEY).equals (msPassword))
            {
                moUserSession.msError = null;
                moUserSession.msCustId = msUserName;
                return true;
            }
            else
            {
                moUserSession.msError = "Password Is Invalid";
            }
        }
        catch (Exception e)
        {
            e.printStackTrace ();
        }

        return false;
    }

    public void setRecored ()
    {
/*
        String lsQuery = "Select product_id, quantity from tempdata where cid='" + moUserSession.msCustId + "'";
        ResultSet loResultSet = DBConn.getRecordFromDB (lsQuery);
        try
        {
            while (loResultSet.next ())
            {
                moUserSession.mvSelsected.add (loResultSet.getString ("product_id"));
            }
        }
        catch (Exception e)
        {
            e.printStackTrace ();
        }
*/
    }

}
